package com.system.healthproject.common;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

@ApiModel
public class ApiResult<T> {
    @ApiModelProperty(name = "code",notes = "状态码")
    private int code;
    @ApiModelProperty(name = "msg",notes = "提示信息")
    private String  msg;
    @ApiModelProperty(name = "data",notes = "返回数据")
    private T data;

    public ApiResult() {
    }

    public ApiResult(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public ApiResult(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> ApiResult<T> success(String msg){
       return new ApiResult<T>(200,msg);
    }
    public static <T> ApiResult<T> failure(String msg){
        return new ApiResult<T>(500,msg);
    }
    public static <T> ApiResult<T> successWithData(String msg, T data){
        return new ApiResult<T>(200,msg,data);
    }
    public static <T> ApiResult<T> successWithData(T data){
        return new ApiResult<T>(200,"成功",data);
    }
    public static <T> ApiResult<T> withBoolean(boolean isSuccess, String success, String failMsg){
        return new ApiResult<T>(isSuccess?200:500,isSuccess?success:failMsg);
    }
    public static <T> ApiResult<T> withBoolean(boolean isSuccess){
        return new ApiResult<T>(isSuccess?200:500,isSuccess?"成功":"失败");
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
